package com.test;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * a线程打印a
 * b变成打印b
 * ...
 */
public class ThreadTest02 {
    private volatile static char i=97;

    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    ThreadTest02.method();
                }
            }).start();
        }
    }

    public static void method(){
        Lock lock = new ReentrantLock();
        lock.lock();
        try{
            System.out.println(Thread.currentThread().getName()+"_"+i);
            i++;
        }finally {
            lock.unlock();
        }
    }
}
